Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formidable

Package Overview
Dependencies
Maintainers
5
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formidable

(DEPRECATED! Install formidable@v2) A node.js module for parsing form data, especially file uploads.

  • 1.2.6
  • v1
  • legacy
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11M
decreased by-4.27%
Maintainers
5
Weekly downloads
 
Created

What is formidable?

The formidable npm package is a Node.js module for parsing form data, especially file uploads. It can handle multipart/form-data, which is used for uploading files through forms.

What are formidable's main functionalities?

File Upload

This code creates an HTTP server that listens for POST requests on the '/upload' path. It uses formidable to parse the incoming form data and handle file uploads.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.parse(req, (err, fields, files) => {
      if (err) {
        res.writeHead(500, { 'content-type': 'text/plain' });
        res.end('Error parsing the files');
        return;
      }
      res.writeHead(200, { 'content-type': 'text/plain' });
      res.write('Files uploaded successfully:\n');
      res.end(JSON.stringify(files, null, 2));
    });
  }
}).listen(8080);

Form Field Parsing

This code snippet demonstrates how to use formidable to parse regular form fields (text inputs, selects, etc.) in addition to file uploads.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/submit' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.parse(req, (err, fields, files) => {
      if (err) {
        res.writeHead(500, { 'content-type': 'text/plain' });
        res.end('Error parsing the form fields');
        return;
      }
      res.writeHead(200, { 'content-type': 'text/plain' });
      res.write('Form fields submitted:\n');
      res.end(JSON.stringify(fields, null, 2));
    });
  }
}).listen(8080);

File Upload Progress

This example shows how to track the progress of a file upload using formidable's 'progress' event, which provides the bytes received and the total bytes expected.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.on('progress', (bytesReceived, bytesExpected) => {
      console.log(`Progress: ${bytesReceived}/${bytesExpected}`);
    });

    form.parse(req, (err, fields, files) => {
      // Handle file upload and response
    });
  }
}).listen(8080);

Other packages similar to formidable

FAQs

Package last updated on 30 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc